package com.example.demojenkins.demo1;


import com.alibaba.fastjson2.JSON;
import com.example.demojenkins.entity.CallBackRes;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
//@Api(value = "Hello 测试 和 redis测试")
public class Demo1 {
    private Logger logger = LoggerFactory.getLogger(this.getClass());
    @Autowired
    private RedisTemplate redisTemplate;

//    @ApiOperation(value="Hello lz 测试", notes="无注意事项")
    @RequestMapping(value = "/testHello",method = RequestMethod.POST)
    public String testHello() {
        return "Hello lz";
    }

//    @ApiOperation(value="Hello lz 2 测试", notes="无注意事项")
    @RequestMapping(value = "/testHello2",method = RequestMethod.POST)
    public String testHello2() {
        return "Hello lz 2";
    }

//    @ApiOperation(value="Hello lz 3 测试", notes="无注意事项")
    @RequestMapping(value = "/testHello3",method = RequestMethod.POST)
    public String testHello3() {
        return "Hello lz 3";
    }

//    @ApiOperation(value="Hello lz 4 测试", notes="无注意事项")
    @RequestMapping(value = "/testHello4",method = RequestMethod.POST)
    public String testHello4() {
        return "Hello lz 4";
    }

//    @ApiOperation(value="redis 测试", notes="无注意事项")
    @RequestMapping(value = "/redisTest",method = RequestMethod.POST)
    public String testRedis() {
        //设置值到redis
        redisTemplate.opsForValue().set("name", "lucy");
        //从redis获取值
        return (String) redisTemplate.opsForValue().get("name");
    }

//    @ApiOperation(value="redis 测试", notes="redis中要有key k1 且有value值")
    @RequestMapping(value = "/redisGet",method = RequestMethod.POST)
    public String testRedisGet() {
        return (String) redisTemplate.opsForValue().get("k1");
    }

    @RequestMapping(value = "/callBack",method = RequestMethod.POST)
    public String testCallBack(@RequestBody Object json) {
        //设置值到redis
        logger.info("活体检测回调结果: json:{}",json);
        CallBackRes success = new CallBackRes("100", "success", "100");
        return JSON.toJSONString(success);
    }

}
